#!/bin/bash

#Defines Webster version number
VERSION=$(cat VERSION)

echo "Webster Webserver"
echo "Version $VERSION"
echo "http://www.foo.bar/"
echo

#Check if 'build' directory exists
#If not, create it
if [ ! -d "build" ]
then
	echo "'build' Directory does not exists"
	echo "Creating 'build' directory"
	echo
	
	mkdir build
fi

#Check if 'build/$VERSION' directory exists
#If not, create it
if [ ! -d "build/$VERSION" ]
then
	echo "'build/$VERSION' Directory does not exists"
	echo "Creating 'build/$VERSION' directory"
	echo
	
	mkdir build/$VERSION
fi

#Check if 'build/$VERSION/Webster' directory exists
#If not, create it
if [ ! -d "build/$VERSION/Webster" ]
then
	echo "'build/$VERSION/Webster' Directory does not exists"
	echo "Creating 'build/$VERSION/Webster' directory"
	echo
	
	mkdir build/$VERSION/Webster
fi

echo "Trying to compile..."
echo

#Iterate trhough all files in 'src' directory,
#echo filename and try to compile
for FILENAME in "`find . -name "*.java"`"
do
	if [ "$FILENAME" = "" ]
	then
		COMPILED=1
	else
		echo "Compiling:"
		echo "$FILENAME"
		javac -d ./build/$VERSION/Webster -cp ./:./src/ -Xlint:unchecked $FILENAME
		COMPILED=0
	fi
done